package com.itheima.mm.service.impl;

import com.itheima.mm.context.BaseContext;
import com.itheima.mm.mapper.QuestionMapper;
import com.itheima.mm.mapper.ReviewLogMapper;
import com.itheima.mm.pojo.Question;
import com.itheima.mm.pojo.ReviewLog;
import com.itheima.mm.service.ReviewLogService;
import com.itheima.mm.utils.DateUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;

/**
 * @Description ReviewLogServiceImpl
 * @Author songyu
 * @Date 2024-06-28
 */
@Service
public class ReviewLogServiceImpl implements ReviewLogService {

    @Autowired
    private ReviewLogMapper reviewLogMapper;

    @Autowired
    private QuestionMapper questionMapper;


    /**
     * 添加审核记录
     *
     * @param reviewLog
     */
    @Transactional
    @Override
    public void add(ReviewLog reviewLog) {
        //补全数据
        reviewLog.setUserId(BaseContext.getCurrentId());
        reviewLog.setCreateDate(DateUtils.parseDate2String(new Date()));

        //添加审核记录
        reviewLogMapper.insert(reviewLog);

        //修改题目审核状态
        Question question = new Question();
        question.setId(reviewLog.getQuestionId());
        question.setReviewStatus(reviewLog.getStatus());
        if(reviewLog.getStatus()==1){
            //审核通过
            question.setStatus(1);//已发布
        }
        questionMapper.update(question);

    }
}